home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / gs3.53 / language.doc < prev    next >
Text File  |  1996-01-10  |  23KB  |  581 lines

  1.    Copyright (C) 1989, 1995 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17.  
  18. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  19.  
  20. This file, language.doc, describes the relationship between the
  21. Ghostscript interpreter and the PostScript language.  This file describes
  22. version 3.53 of Ghostscript.
  23.  
  24. For an overview of Ghostscript and a list of the documentation files, see
  25. README.
  26.  
  27. The Ghostscript interpreter, except as noted below, is intended to execute
  28. properly any source program written in the (Level 2) PostScript language as
  29. defined in the December 1990 printing of the PostScript Language Reference
  30. Manual (Second Edition) published by Addison-Wesley (ISBN 0-201-18127-4).
  31. However, the interpreter is configurable in ways that can restrict it to
  32. various subsets of this language.  Specifically, the base interpreter
  33. accepts the Level 1 subset of the PostScript language, as defined in the
  34. first edition of the PostScript Language Reference Manual, ISBN
  35. 0-201-10174-2, Addison-Wesley, 1985, plus the file system, version 25.0
  36. language, and miscellaneous additions listed in sections A.1.6, A.1.7, and
  37. A.1.8 of the Second Edition respectively, including allowing a string
  38. operand for the 'status' operator.  The base interpreter may be configured
  39. by adding any combination of the following:
  40.  
  41.     - The ability to process PostScript Type 1 fonts.  This facility is
  42. normally included in the interpreter.
  43.  
  44.     - The CMYK color extensions listed in section A.1.4 of the Second
  45. Edition (including colorimage).  These facilities are only available if the
  46. color, dps, or level2 feature was selected at the time that Ghostscript was
  47. compiled and linked.
  48.  
  49.     - The Display PostScript extensions listed in section A.1.3
  50. of the Second Edition, but excluding the operators listed in section
  51. A.1.2.  These facilities are only available if the dps feature or the
  52. level2 feature was selected at the time that Ghostscript was compiled
  53. and linked.
  54.  
  55.     - The composite font extensions listed in section A.1.5 of the
  56. Second Edition, and the ability to handle Type 0 fonts.  These facilities
  57. are only available if the compfont feature or the level2 feature was
  58. selected at the time that Ghostscript was compiled and linked.
  59.  
  60.     - The PostScript Level 2 "filter" facilities aside from DCTEncode
  61. and DCTDecode filters.  These facilities are only available if the filter,
  62. dps, or level2 feature was selected at the time that Ghostscript was
  63. compiled and linked.
  64.  
  65.     - The PostScript Level 2 DCTEncode and DCTDecode filters.  These
  66. facilities are only available if the dct or level2 feature was selected at
  67. the time that Ghostscript was compiled and linked.
  68.  
  69.     - All the other PostScript Level 2 operators and facilities listed
  70. in section A.1.1 of the Second Edition and not listed in any of the other
  71. A.1.n sections.  These facilities are only available if the level2 feature
  72. was selected at the time that Ghostscript was compiled and linked.
  73.  
  74. Adding all of these produces a full Level 2 PostScript language
  75. interpreter.
  76.  
  77. Ghostscript also includes a number of operators defined below that are not
  78. in the PostScript language.
  79.  
  80. Implementation limits
  81. =====================
  82.  
  83. The following implementation limits correspond to those in Table B.1 and
  84. B.2 of the Second Edition.  Those marked with * are different from the ones
  85. in the Second Edition.
  86.  
  87. Architectural limits
  88. --------------------
  89.  
  90. integer        32-bit two's complement integer
  91. real        single-precision IEEE float
  92. *array
  93.     On 16-bit systems:    8191 elements
  94.     On 32-bit systems:    65535 elements
  95. *dictionary
  96.     On 16-bit systems:    8190 elements
  97.     On 32-bit systems:    65534 elements
  98. *string        65535 characters
  99. *name        16383 characters
  100. filename    100 characters
  101. *save level    none (capacity of memory)
  102. *gsave level    none (capacity of memory)
  103.  
  104. Typical memory limits in Level 1
  105. --------------------------------
  106.  
  107. userdict        200
  108. FontDirectory        100
  109. *operand stack        800
  110. dictionary stack    20
  111. execution stack        250
  112. *interpreter level    none (capacity of memory)
  113. *path            none (capacity of memory)
  114. dash            11
  115. *VM            capacity of memory
  116. *file            determined by operating system
  117. *image            65535 values (samples x components) for 1, 2, 4,
  118.               or 8-bit samples; 32767 values for 12-bit samples
  119.  
  120. Other differences in VM consumption
  121. -----------------------------------
  122.  
  123. Packed array elements occupy either 2 bytes or 8 bytes.  The average
  124. element size is probably about 5 bytes.
  125.  
  126. Names occupy 12 bytes plus the space for the string.
  127.  
  128. Ghostscript-specific additions
  129. ==============================
  130.  
  131. Miscellaneous
  132. -------------
  133.  
  134. ^D and ^Z are self-delimiting tokens, like [ and ].  They are initially
  135. defined as empty procedures so that they will be ignored in the input
  136. stream.
  137.  
  138. run can take either a string or a file as its argument.  In the latter
  139. case, it just runs the file, closing it at the end, and trapping errors
  140. just as for the string case.
  141.  
  142. Mathematical operators
  143. ----------------------
  144.  
  145.     <number> arccos <number>
  146.         Computes the arc cosine of a number between -1 and 1.
  147.  
  148.     <number> arcsin <number>
  149.         Computes the arc sine of a number between -1 and 1.
  150.  
  151. String operators
  152. ----------------
  153.  
  154.     <state> <fromString> <toString> .type1encrypt <newState> <toSubstring>
  155.         Encrypts fromString according to the algorithm for Adobe
  156.           Type 1 fonts, writing the result into toString.
  157.           toString must be at least as long as fromString or a
  158.           rangecheck error occurs.  state is the initial state of
  159.           the encryption algorithm (a 16-bit non-negative
  160.           integer); newState is the new state of the algorithm.
  161.  
  162.     <state> <fromString> <toString> .type1decrypt <newState> <toSubstring>
  163.         Decrypts fromString according to the algorithm for Adobe
  164.           Type 1 fonts, writing the result into toString.  Other
  165.           specifications are as for type1encrypt.
  166.  
  167. Relational operators
  168. --------------------
  169.  
  170.     <number|string> <number|string> max <number|string>
  171.         Returns the larger of two numbers or strings.
  172.  
  173.     <number|string> <number|string> min <number|string>
  174.         Returns the smaller of two numbers or strings.
  175.  
  176. File operators
  177. --------------
  178.  
  179.     <string> findlibfile <foundstring> <file> true
  180.     <string> findlibfile <string> false
  181.         Opens the file of the given name for reading, searching
  182.           through directories as described in use.doc.  If the
  183.           search fails, findlibfile simply pushes false on the
  184.           stack and returns, rather than causing an error.
  185.  
  186.     <file> <integer> unread -
  187.          Pushes back the last-read character onto the front of the
  188.           file.  If the file is only open for writing, or if the
  189.           integer argument is not the same as the last character
  190.           read from the file, causes an ioerror error.  May also
  191.           cause an ioerror if the last operation on the file was not
  192.           a reading operation.
  193.  
  194.     <file> <device> writeppmfile -
  195.         Writes the contents of the device, which must be an image
  196.           device, onto the file, in Portable PixMap (ppm) format.
  197.           Does not close the file.
  198.  
  199. Ghostscript also supports the following IODevice in addition to a subset of
  200. those defined in the Adobe documentation: %pipe%command, which opens a pipe
  201. on the given command.  This is only supported on operating systems that
  202. provide popen (primarily Unix systems, and not all of those).
  203.  
  204. Path operators
  205. --------------
  206.  
  207.     <x> <y> <width> <height> .rectappend -
  208.     <numarray> .rectappend -
  209.     <numstring> .rectappend -
  210.         Appends a rectangle or rectangles to the current path, in
  211.           the same manner as rectfill, rectclip, etc.  Only
  212.           defined if the dps option is selected.
  213.  
  214. Painting operators
  215. ------------------
  216.  
  217. Ghostscript supports an experimental extension of the PostScript imaging
  218. model to include RasterOp and some related facilities.  This extension is
  219. only available if the rasterop option was selected when building
  220. Ghostscript.
  221.  
  222. With the RasterOp extension, imaging operations compute a function D =
  223. f(D,S,T) in RGB space, where f is an arbitrary 3-input Boolean function, D
  224. is the destination (frame buffer or print buffer), S is the source
  225. (described below), and T is the texture (the current PostScript color, which
  226. may be a pattern).  The source and texture depend on the PostScript imaging
  227. operation:
  228.  
  229.     - For fill and stroke, the source is solid black, covering the
  230.     region to be painted; the texture is the current PostScript color.
  231.  
  232.     - For show and imagemask, the source is solid black, covering the
  233.     pixels to be painted; the texture is the current PostScript color.
  234.  
  235.     - For image and colorimage, the source is the image data; the
  236.     texture depends on an optional Boolean parameter, CombineWithColor,
  237.     in the image dictionary.  If CombineWithColor is false (the
  238.     default), the texture is solid black.  If CombineWithColor is true,
  239.     the texture is the current color.  For the non-dictionary form of
  240.     the image operator, CombineWithColor is considered to be false.
  241.  
  242. The rasterop option adds the following operators:
  243.  
  244.     <int8> .setrasterop -
  245.         Sets the RasterOp function in the graphics state.
  246.           The default function is 252, Source | Texture.
  247.  
  248.     - .currentrasterop <int8>
  249.         Returns the current RasterOp function.
  250.  
  251.     <bool> .setsourcetransparent -
  252.         Sets source transparency in the graphics state.  When source
  253.           transparency is true, white source pixels prevent storing
  254.           into the destination, regardless of what the RasterOp
  255.           function returns.  The default source transparency is
  256.           false.
  257.  
  258.     - .currentsourcetransparent <bool> -
  259.         Returns the current source transparency.
  260.  
  261.     <bool> .settexturetransparent -
  262.         Sets texture transparency in the graphics state.  When texture
  263.           transparency is true, white texture pixels prevent storing
  264.           into the destination, regardless of what the RasterOp
  265.           function returns.  The default texture transparency is
  266.           false.
  267.  
  268.     - .currenttexturetransparent <bool> -
  269.         Returns the current texture transparency.
  270.  
  271. For more information on RasterOp and transparency, please consult chapter 5
  272. of the "PCL 5 Color Technical Reference Manual", Hewlett-Packard Manual Part
  273. No. 5961-0635.
  274.  
  275. Filters
  276. -------
  277.  
  278. Ghostscript supports all the standard PostScript Level 2 filters.  In
  279. addition, Ghostscript supports the following non-standard filters:
  280.  
  281.     <target> <seed_integer> /eexecEncode filter <file>
  282.         Creates a filter for encrypting data into the
  283.           eexec encrypted format described in the
  284.           Adobe Type 1 Font Format documentation.  The
  285.           seed_integer must be 55665 for proper operation.
  286.           This filter produces binary output and does not
  287.           include the initial 4 garbage bytes.
  288.  
  289.     <source> <seed_integer> /eexecDecode filter <file>
  290.         Creates a filter for decrypting data that has been
  291.           encrypted using eexec encryption as described in the
  292.           Adobe Type 1 Font Format documentation.  The
  293.           seed_integer must be 55665 for proper operation.
  294.  
  295.     <source> <hex_boolean> /PFBDecode filter <file>
  296.         Creates a filter that decodes data in .PFB format, the
  297.           usual semi-binary representation for Type 1 font files
  298.           on IBM PC and compatible systems.  If hex_boolean is true,
  299.           binary packets are converted to hex; if false, binary
  300.           packets are not converted.
  301.  
  302.     <target> /BCPEncode filter <file>
  303.     <source> /BCPDecode filter <file>
  304.         Create filters that implement the Adobe Binary
  305.           Communications Protocol.  See Adobe documentation for
  306.           details.
  307.  
  308.     <target> /TBCPEncode filter <file>
  309.     <source> /TBCPDecode filter <file>
  310.         Create filters that implement the Adobe Tagged Binary
  311.           Communications Protocol.  See Adobe documentation for
  312.           details.
  313.  
  314. Various versions of Ghostscript may also support other non-standard filters
  315. for experimental purposes.  The current version includes the following
  316. non-standard filters, which are not documented further.  No guarantee is
  317. made that these filters will exist in compatible form, or at all, in future
  318. versions.
  319.  
  320.     <target/source> <string> ByteTranslateEncode/Decode
  321.     <target> <int> BigStringEncode
  322.     <target/source> <dict> BoundedHuffmanEncode/Decode
  323.         FirstBitLowOrder <bool> false
  324.         MaxCodeLength <int> 16
  325.         EndOfData <bool> true
  326.         EncodeZeroRuns <int> 256
  327.         Tables <int_array>
  328.     <target/source> <dict> BWBlockSortEncode/Decode
  329.         BlockSize <int> 16384
  330.     <target/source> MoveToFrontEncode/Decode
  331.  
  332. Ghostscript also supports a non-standard optional dictionary operand for
  333. the LZWDecode filter, with the following keys (all optional):
  334.  
  335.     InitialCodeLength <integer>
  336.         An integer between 2 and 11 specifying the initial number
  337. of data bits per code.  Note that the actual initial code length is 1
  338. greater than this, to allow for the reset and end-of-data code values.
  339. Default value: 8.
  340.  
  341.     FirstBitLowOrder <boolean>
  342.         If true, codes appear with their low-order bit first.
  343. Default value: false.
  344.  
  345.     BlockData <boolean>
  346.         If true, the data is broken into blocks in the manner
  347. specified for the GIF file format.  Default value: false.
  348.  
  349.     EarlyChange <integer>
  350.         If 0, codes become one bit longer one code earlier than
  351. they need to; if 1, codes become one bit longer as specified in the
  352. PostScript Language Reference Manual.  Default value: 1.
  353.  
  354. Virtual memory operators
  355. ------------------------
  356.  
  357.     <save> .forgetsave -
  358.         Cancels the effect of a save -- makes it as though the
  359.           save never happened.
  360.  
  361. Miscellaneous operators
  362. -----------------------
  363.  
  364.     - currenttime <number>
  365.         Returns the current value of a continuously-running timer,
  366.           in minutes.  The initial value of this timer is undefined.
  367.  
  368.     <string> getenv <string> true
  369.     <string> getenv false
  370.         Looks up a name in the shell environment.  If the name is
  371.           found, returns the corresponding value and true; if the
  372.           name is not found, returns false.
  373.  
  374.     <name> <array> makeoperator <operator>
  375.         Constructs and returns a new operator that is actually the
  376.           given procedure in disguise.  The name is only used for
  377.           printing.  The operator has the executable attribute.
  378.  
  379.     <string> <boolean> .setdebug -
  380.         If the Ghostscript interpreter was built with the DEBUG
  381.           flag set, sets or resets any subset of the debugging
  382.           flags normally controlled by -Z in the command line.
  383.           Has no effect otherwise.
  384.  
  385.     - .oserrno <errno>
  386.         Returns the error code for the most recent OS error.
  387.  
  388.     - .oserror <string>
  389.         Returns the error string for the most recent OS error.
  390.  
  391. Device operators
  392. ----------------
  393.  
  394.     <device> copydevice <device>
  395.         Copies a device.
  396.  
  397.     <index> .getdevice <device>
  398.         Returns a device from the set of devices known to the
  399.           system.  The first device, which is default, is numbered
  400.           0.  If the index is out of range, causes a rangecheck
  401.           error.
  402.  
  403.     <matrix> <width> <height> <palette> makeimagedevice <device>
  404.         Makes a new device that accumulates an image in memory.
  405.           matrix is the initial transformation matrix: it must be
  406.           orthogonal (i.e., [a 0 0 b x y] or [0 a b 0 x y]).
  407.           palette is a string of 2^N or 3*2^N elements, specifying
  408.           how the 2^N possible pixel values will be interpreted.
  409.           Each element is interpreted as a gray value, or as RGB
  410.           values, multiplied by 255.  For example, if you want
  411.           a monochrome image for which 0=white and 1=black, the
  412.           palette should be <ff 00>; if you want a 3-bit deep
  413.           image with just the primary colors and their complements
  414.           (ignoring the fact that 3-bit images are not supported),
  415.           the palette might be <000000 0000ff 00ff00 00ffff
  416.           ff0000 ff00ff ffff00 ffffff>.  At present, the palette
  417.           must contain exactly 2, 4, 16, or 256 entries,
  418.           and must contain an entry for black and an entry
  419.           for white; if it contains any entries that aren't black,
  420.           white, or gray, it must contain at least the six primary
  421.           colors (red, green, blue, and their complements cyan,
  422.           magenta, and yellow); aside from this, its contents are
  423.           arbitrary.
  424.         Alternatively, palette can be null.  This is interpreted
  425.           as 24-bit-per-pixel color, where the three bytes of each
  426.           pixel are respectively R, G, and B.
  427.         Note that one can also make an image device (with the same
  428.           palette as an existing image device) by copying a device
  429.           using the copydevice operator.
  430.  
  431.     <matrix> <width> <height> <palette> <word?> makewordimagedevice
  432.         <device>
  433.         Makes an image device as described above.  word? is a
  434.           Boolean value indicating whether the data should be stored
  435.           in a word-oriented format internally.  No ordinary
  436.           PostScript programs should use this operator.
  437.  
  438.     <device> <index> <string> copyscanlines <substring>
  439.         Copies one or more scan lines from an image device into a
  440.           string, starting at a given scan line in the image.
  441.           The data is in the same format as for the image
  442.           operator.  Error if the device is not an image device or
  443.           if the string is too small to hold at least one complete
  444.           scan line.  Always copies an integral number of scan
  445.           lines.
  446.  
  447.     <device> setdevice -
  448.         Sets the current device to the specified device.  Also
  449.           resets the transformation and clipping path to the
  450.           initial values for the device.
  451.  
  452.     - currentdevice <device>
  453.         Gets the current device from the graphics state.
  454.  
  455.     <device> getdeviceprops <mark> <name1> <value1> ... <namen> <valuen>
  456.         Gets all the properties of a device.  Currently defined
  457.           names and values for all devices are:
  458.             BitsPerPixel <integer>
  459.                 Usually read-only.  Number of bits per pixel.
  460.             .HWMargins [<4 floats>]
  461.                 Size of non-imageable regions around edges
  462.                   of page, in 1/72" units.
  463.             HWSize [<integer> <integer>]
  464.                 X and Y size in pixels.
  465.             Name <string>
  466.                 Read-only.  The device name.
  467.                   Currently, same as OutputDevice.
  468.             Colors, GrayValues, RedValues, GreenValues,
  469.               BlueValues, ColorValues
  470.                 As for the 'deviceinfo' operator of
  471.                   Display PostScript.
  472.         In addition, the following are defined per Adobe's
  473.           documentation for the setpagedevice operator:
  474.             Duplex (if supported)
  475.             HWResolution
  476.             ImagingBBox
  477.             Margins
  478.             NumCopies (for printers only)
  479.             Orientation (if supported)
  480.             OutputDevice
  481.             PageSize
  482.             ProcessColorModel
  483.         Some devices may only allow certain values for
  484.           HWResolution and PageSize.  The null device ignores
  485.           attempts to set PageSize; its size is always [0 0].
  486.         Red/Green/Blue/ColorValues are only defined if Colors > 1.
  487.         For printers, the following are also defined:
  488.             BufferSpace <integer>
  489.                 Buffer space for band lists, if the bitmap
  490.                   is too big to fit in RAM.
  491.             MaxBitmap <integer>
  492.                 Maximum space for a full bitmap in RAM.
  493.             OutputFile <string>
  494.                 () means send to printer directly,
  495.                   otherwise specifies the file name for
  496.                   output; a %d is replaced by the page #;
  497.                   on Unix systems, (|command) writes to a pipe
  498.             OpenOutputFile <boolean>
  499.                 If true, open the device's output file
  500.                   when the device is opened, rather than
  501.                   waiting until the first page is ready to
  502.                   print.
  503.             PageCount <integer>
  504.                 Read-only.  Counts the number of pages
  505.                   printed on the device.
  506.  
  507.     <mark> <name1> <value1> ... <namen> <valuen> <device>
  508.         putdeviceprops <device>
  509.         Sets properties of a device.  May cause undefined,
  510.           typecheck, rangecheck, or limitcheck errors.
  511.  
  512.     - flushpage -
  513.         On displays, flushes any buffered output, so that it
  514.           is guaranteed to show up on the screen; on printers,
  515.           has no effect.
  516.  
  517. Ghostscript supports the following page device parameters in addition to the
  518. ones documented by Adobe and the ones described under getdeviceprops above:
  519.  
  520.     ViewerPreProcess    procedure
  521.         Specifies a procedure to be applied to the page device
  522.           dictionary before any other processing is done.  The
  523.           procedure may not alter the dictionary, but it may return
  524.           a modified copy.  This "hook" is provided for use by
  525.           viewing programs.
  526.  
  527. Character operators
  528. -------------------
  529.  
  530.     <string> <bool> .charboxpath -
  531.         For each character C in the rendering of <string>, let the
  532.           bounding box of C *in device space* be the four
  533.           *user-space* points p1x/y, p2x/y, p3x/y, and p4x/y.  For
  534.           each character in order, .charboxpath appends the
  535.           following to the current path:
  536.             - If <bool> is true, the equivalent of:
  537.                 p1x p1y moveto
  538.                 p2x p2y lineto
  539.                 p3x p3y lineto
  540.                 p4x p4y lineto
  541.                 closepath
  542.             - If <bool> is false, the equivalent of:
  543.                 p1x p1y moveto
  544.                 p3x p3y lineto
  545.           In either case, this creates a path whose pathbbox is the
  546.           bbox of the string.
  547.  
  548.     <string> .type1addpath -
  549.     <string> <lsbx> <lsby> .type1addpath -
  550.         Adds the description of a character to the current
  551.           path.  The string argument is a scalable
  552.           description encoded in Adobe Type 1 format.  This
  553.           operator, like setcharwidth and setcachedevice, is
  554.           only valid in the context of a show operator.  It
  555.           uses information from the current font, in addition
  556.           to the argument(s).
  557.         The optional lsbx and lsby arguments are left side
  558.           bearing values that override the ones in the
  559.           character outline.
  560.  
  561.     <font> <char> %Type1BuildChar -
  562.         This is not a new operator: rather, it is a name known
  563.           specially to the interpreter.  Whenever the interpreter
  564.           needs to render a character (during a ...show,
  565.           stringwidth, or charpath), it looks up the name
  566.           BuildChar in the font dictionary to find a procedure to
  567.           run.  If it does not find this name, and if the FontType
  568.           is 1, the interpreter instead uses the value (looked up
  569.           on the dictionary stack in the usual way) of the name
  570.           %Type1BuildChar.
  571.         The standard definition of %Type1BuildChar is in gs_fonts.ps.
  572.           Users should not need to redefine %Type1BuildChar, except
  573.           perhaps for tracing or debugging.
  574.  
  575.     <font> <name> %Type1BuildGlyph
  576.         Provides the Type 1 implementation of BuildGlyph.
  577.  
  578. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  579.  
  580. PostScript is a trademark of Adobe Systems, Incorporated.
  581.